import logging, math, random
from prepconf import loadhosts

log = logging.getLogger('initsleep')

def writeInitSleep():
    random.seed(123)
    hosts = loadhosts()
    f = open("initsleep.txt", "w")
    for host in hosts:
        initsleep = int(random.uniform(10, 180))
        if host=="planetlab4.singaren.net.sg":
            initsleep = 0
        f.write("initsleep,"+host+"="+str(initsleep)+"\n");
    f.close()


if __name__=="__main__":
    logging.basicConfig(level=logging.DEBUG)
    try:
        open("initsleep.txt")
    except IOError:
        log.info("initsleep.txt missing; creating it")
        writeInitSleep()

    log.info("all done")
